package com.example.customviewtest.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

import com.example.customviewtest.R;

public class View1 extends View {


    private Paint mPaint;
    private Path mPath;

    public View1(Context context) {
        this(context, null);
    }

    public View1(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public View1(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initPaint();
    }

    private void initPaint() {
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);//抗锯齿
        mPaint.setColor(Color.RED);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(10);//设置线的宽度
        mPath = new Path();

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(1000, 1000);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawCircle(300.0f, 300.0f, 200.0f, mPaint);
        canvas.drawColor(Color.parseColor("#88888888"));
        mPaint.setColor(Color.BLACK);
        canvas.drawRect(100, 600, 500, 800, mPaint);
        mPaint.setColor(Color.YELLOW);
        float[] points = {0, 0, 50, 50, 50, 100, 100, 50, 100, 100, 150, 50, 150, 100};
// 绘制四个点：(50, 50) (50, 100) (100, 50) (100, 100)
        canvas.drawPoints(points, mPaint);

        mPath.addArc(200, 200, 400, 400, -225, 225);
        mPath.arcTo(400, 200, 600, 400, -180, 225, false);
        mPath.lineTo(400, 542);
        canvas.drawPath(mPath, mPaint);
        mPaint.setColor(Color.RED);
        mPaint.setTextSize(84);
        mPaint.setStyle(Paint.Style.FILL);
        canvas.drawText("View1", 100.0f, 100.0f, mPaint);
    }
}
